<?php

namespace Liuhelong\LaravelAdmin\Wechat\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Encore\Admin\Traits\DefaultDatetimeFormat;

class WechatOffiaccountMessageFunction extends Model
{
    use HasFactory,DefaultDatetimeFormat;
	public function scopeStatus($query)
    {
        return $query->where('status', 1);
    }
	protected $appends = ['text','reply_media','news'];
	protected $medias = ['image','voice','video'];
	
	public function setTextAttribute($value)
    {
        $this->attributes['reply_content'] = $value;
    }
	public function setReplyMediaAttribute($value)
    {
        $this->attributes['reply_content'] = $value;
    }
	public function setNewsAttribute($value)
    {
        $this->attributes['reply_content'] = $value;
    }
	
	public function getTextAttribute()
    {
        return $this->reply_type=='text'?$this->reply_content:'';
    }
	public function getReplyMediaAttribute()
    {
        return in_array($this->reply_type,$this->medias)?$this->reply_content:'';
    }
	public function getNewsAttribute()
    {
        return $this->reply_type=='news'?$this->reply_content:'';
    }
	
	
    public function cs_messages(){
        return $this->belongsToMany(WechatOffiaccountCsMessage::class,"wechat_offiaccount_cm_mf");
    }
}
